#include <algorithm>
using namespace std;

int Partition(int q[], int low, int high)
{
    int pivot=q[low];

    while(low<high)
    {
        while(low<high&&q[high]>=pivot) --high;
        q[low]=q[high];
        while(low<high&&q[low]<=pivot) ++low;
        q[high]=q[low];
    }
    
    q[low]=pivot;
    return low; 
}

void quick_sort(int q[], int low, int high)
{
    if(low<high)
    {
        int pivotpos=Partition(q, low, high);
        quick_sort(q, low, pivotpos-1); quick_sort(q, pivotpos+1, high);
    }
}
